package cn.wolfcode.wolf2w.business.listen;

import cn.wolfcode.wolf2w.api.domain.Strategy;
import cn.wolfcode.wolf2w.api.domain.StrategySearch;
import cn.wolfcode.wolf2w.business.repository.StrategyRepository;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 浪兎兎
 * @since 2025-06-16 13:38
 */
@Component
public class StrategyListener {
    @Autowired
    private StrategyRepository strategyRepository;
    @RabbitListener(queues = {"strategyQueue"})
    public void onMessage(String message) {
        Strategy strategy = JSON.parseObject(message, Strategy.class);
        StrategySearch strategySearch = new StrategySearch();
        BeanUtils.copyProperties(strategy, strategySearch);
        strategyRepository.save(strategySearch);
    }
}
